package com.vvip.app;

import com.vvip.adapter.QuoteItem;

import com.vvip.adapter.QuoteListAdapter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

import android.app.Activity;
import android.content.Intent;

import android.os.Bundle;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class QuoteActivity extends Activity implements
		AdapterView.OnItemClickListener {

	private ArrayList<QuoteItem> quotes;
	private QuoteItem item;
	private QuoteListAdapter adapter;
	private ListView listView;
	private TextView dateView;
 
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.quote_list);

		//ÇöÀç ³¯Â¥¿¡ ´ëÇÑ StringÀ» ±¸ÇÑ´Ù.
		SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd", Locale.KOREA);
		Date current = new Date();
		Calendar a = new GregorianCalendar(Locale.KOREA);
		String dd = "2011-1-2";
		
		String date = formater.format(current);
		
		//View °´Ã¼¿Í layout ÆÄÀÏÀÇ ViewµéÀ» ¸ÊÇÎÇÑ´Ù.
		listView = (ListView) findViewById(R.id.quote_list_view);
		dateView = (TextView) findViewById(R.id.date_view);

		//QuoteItemÀÇ List¸¦ »ý¼º ÇÑ ÈÄ QuoteItem ÀÇ °´Ã¼¸¦ »ý¼ºÇØ Ãß°¡ÇÑ´Ù. 
		quotes = new ArrayList<QuoteItem>();
		item = new QuoteItem("»ï¼ºÀüÀÚ", "100,000,000");
		quotes.add(item);
		item = new QuoteItem("¿¤ÁöÀüÀÚ", "50,000,000");
		quotes.add(item);
		
		//QuoteItem¿¡ ´ëÇÑ Adapter¿Í ListViewÀÇ °¢°¢ÀÇ Ç×¸ñÀ» Ç¥ÇöÇÏ´Â LayoutÆÄÀÏÀ» ¼³Á¤ÇÑ´Ù.
		adapter = new QuoteListAdapter(this, R.layout.quote_list_item, quotes);
		
		//ListView Adapter·Î QuoteListAdapterÀ» ¼³Á¤ÇÑ´Ù.
		listView.setAdapter(adapter);		
		//ListViewÀÇ Ç×¸ñ ¼±ÅÃ Event¿¡ ´ëÇÑ Ã³¸®¸¦ ÀÌ Å¬·¡½º·Î ÇÑ´Ù.
		listView.setOnItemClickListener(this);
		
		//³¯Â¥¸¦ ¼³Á¤ÇÑ´Ù.
		//dateView.setText(date);
          

	}

	/**
	 * ListVew Ç×¸ñ ¼±ÅÃ ÇÚµé·¯<br>
	 * ¼±ÅÃµÈ Ç×¸ñÀÇ ÀÌ¸§À» ³Ñ±â¸ç QuoteTableActivity¸¦ È£ÃâÇÑ´Ù.
	 */
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = new Intent(this, com.vvip.app.QuoteTableActivity.class);
		intent.putExtra("EXTRA_DATA", quotes.get(position).getName());
		startActivity(intent);
		
	}
	
	
}
